#include "BaseScreen.h"
#include "SimpleAudioEngine.h"
#include "../FlowController.h"

using namespace cocos2d;
using namespace CocosDenshion;

BaseScreen* BaseScreen::createLayer()
{
    // 'scene' is an autorelease object
    //CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    BaseScreen *layer = BaseScreen::create();

    // add layer as a child to scene
    //scene->addChild(layer);

    // return the scene
    return layer;
}

BaseScreen::BaseScreen()
{
}

BaseScreen::~BaseScreen()
{
	_myFlowController = 0;
}

// on "init" you need to initialize your instance
bool BaseScreen::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    this->setKeypadEnabled(true); //enable for backkey button
    this->setTouchEnabled(true); //enable touches

    return true;
}

/*
 * @function: laodScreen
 * @brief: Load the screen with the background image
 * @param flowcontroller: Reference the FlowController
 * @param bgfilename: Filename of the background image
 */
void BaseScreen::loadScreen(FlowController *flowcontroller)
{
	CCSize _screenSize = CCDirector::sharedDirector()->getWinSize();
	_myFlowController = flowcontroller;

	//Add background
	CCSprite *background = CCSprite::create(_bgFileName->getCString());

	//calculate scale factor based on height restriction
	_scaleFactor = ((float)_screenSize.height) / background->boundingBox().size.height;
	background->setScale(_scaleFactor);
	background->setPosition(ccp(_screenSize.width/2,_screenSize.height/2));
	this->addChild(background);
}
